using System;
using System.Collections.Generic;
using System.Text;
using QuanLySim.DTO;
using System.Data;

namespace QuanLySim.DAO
{
    class clsQuanLyDAO
    {
        #region "variable"
        private string m_Erorr;
        private clsCommand m_Command;
        #endregion

        #region "property"
        public string ERORR
        {
            get { return m_Erorr; }
            set { m_Erorr = value; }
        }
        #endregion

        #region "method"
        public clsQuanLyDAO()
        {
            m_Erorr = "";
            m_Command = new clsCommand();
        }

        public bool Insert(clsQuanLyDTO QuanLyDto)
        {
            m_Command = new clsCommand();
            string strInsert = "INSERT INTO QUANLY (TENDANGNHAP, TENNGUOITHEM, GIOITINH, MATKHAU) VALUES (";
            strInsert += "'" + QuanLyDto.TENDANGNHAP + "',";
            strInsert += "'" + QuanLyDto.HOTENQL + "',";
            strInsert += "'" + QuanLyDto.GIOITINH + "',";
            strInsert += "'" + QuanLyDto.MATKHAU + "')";

            return m_Command.ExecuteNonQuery(strInsert);
        }

        public bool Delete(clsQuanLyDTO QuanLyDto)
        {
            m_Command = new clsCommand();
            string strDelete = "DELETE FROM QUANLY WHERE TENDANGNHAP = ";
            strDelete += "'" + QuanLyDto.TENDANGNHAP + "'";

            return m_Command.ExecuteNonQuery(strDelete);
        }

        public bool Update(clsQuanLyDTO QuanLyDto)
        {
            m_Command = new clsCommand();
            string strUpdate = "UPDATE QUANLY SET TENNGUOITHEM = '" + QuanLyDto.HOTENQL + "'"; 
            strUpdate += " WHERE TENDANGNHAP = '" + QuanLyDto.TENDANGNHAP + "'";

            return m_Command.ExecuteNonQuery(strUpdate);
        }

        public DataTable QuanLy()
        {
            m_Command = new clsCommand();
            DataTable table = new DataTable();
            string strSelect = "SELECT TENDANGNHAP, TENNGUOITHEM, GIOITINH FROM QUANLY";
            if (m_Command.Connect())
            {
                table = m_Command.Select(strSelect);
                m_Command.CloseConnect();
                return table;
            }
            m_Erorr = m_Command.ERORR;
            return null;
        }
        #endregion
    }
}
